<template>
  <el-card>
    <el-dialog title="考勤内容" :visible.sync="dialogAttVisible" width="95%">{{this.info}}</el-dialog>
    <el-table :data="templateData" style="width: 100%;margin-top:2px;">
      <el-table-column prop="attendanceItemName" label="考勤项名称" width="150"></el-table-column>
      <el-table-column prop="targetWeight" label="考评权重" width="120"></el-table-column>
      <el-table-column prop="attendanceTarget" label="考勤指标" width="150"></el-table-column>
      <el-table-column prop="attendanceInfo" label="考勤内容" width="600">
        <!-- <template slot-scope="scope">
          <el-button type="text" size="small" @click="show(scope.row.attendanceInfo)">查看内容</el-button>
        </template> -->
      </el-table-column>
    </el-table>
  </el-card>
</template>
<script>
export default {
  data() {
    return {
      templateData: null,
      departId: null,
      code: null,
      corpId: null,
      info: null,
      dialogAttVisible: false
    };
  },
  created() {
    this.getJsApiTeckit();
  },
  methods: {
    async getJsApiTeckit() {
      var result = await this.$httpd.get("/DingDingSecurity/GetJsapiTicket");
      if (result.status != 200) {
        this.$message.error("获取钉钉信息出错");
        return;
      }
      this.corpId = result.data.corpId;
      this.getCode(this.corpId);
    },
    //获取个人免登code
    getCode(corpId) {
      var that = this;
      that.$dd.ready(() => {
        that.$dd.runtime.permission.requestAuthCode({
          corpId: corpId, // 企业id
          onSuccess: function(info) {
            that.code = info.code;
            that.getDeparts(that.code);
          }
        });
      });
    },
    async getDeparts(code) {
      var result = await this.$httpd.get(
        `/EmpSalary/GetdepartmentById?code=${code}`
      );
      if (result.status != 200) {
        this.$message.error("获取部门数据出错");
        return;
      }
      this.departId = result.data.parentid;
      this.getTemp(this.departId);
    },
    async getTemp(departId) {
      var result = await this.$httpd.get(
        `/AttendanceTemplate/QueryAttendanceTemplates?dePartId=${departId}`
      );
      if (result.status != 200) {
        this.$message.error("获取考勤模板数据出错");
        return;
      }
      this.templateData = result.data.data;
    },
    show(info) {
      this.dialogAttVisible = true;
      this.info = info;
    }
  }
};
</script>